package com.onec.service.thread.group;

import java.util.Random;

public class TaskRun implements Runnable {


    @Override
    public void run() {

        int result = 0;
        Random random = new Random(Thread.currentThread().getId());
        while (true) {
            result = 1000 / ((int) random.nextDouble() * 10000);
            if (Thread.currentThread().isInterrupted()) {
                System.out.println("--------->" + Thread.currentThread().getId());
            }
        }
    }

    public static void main(String[] args) {
        int number = Runtime.getRuntime().availableProcessors();
        MyThreadGroup myThreadGroup = new MyThreadGroup("MyThreadGroup");

        TaskRun taskRun = new TaskRun();

        for (int i = 1; i < number; i++) {
            Thread thread = new Thread(myThreadGroup, taskRun);
            thread.start();
        }

        System.out.println("--->" + myThreadGroup.activeCount());
        myThreadGroup.list();

        Thread[] threads = new Thread[myThreadGroup.activeCount()];
        for (int t = 0; t < threads.length; t++) {
            System.out.println("--->" + threads[t].getName() + "--:" + threads[t].getState());
        }
    }
}
